<%--
  Created by IntelliJ IDEA.
  User: Vadim
  Date: 7/21/14
  Time: 1:01 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib uri="/WEB-INF/Helper.tld" prefix="sz"%>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Edit Uploads</title>
    <!-- Make sure the path to CKEditor is correct. -->
    <link rel="stylesheet" href="../content/style/style.css">
    <%--<script src="http://code.jquery.com/jquery-1.9.0.js"></script>--%>
    <script src="../content/scripts/jquery.min.js"></script>
    <script type='text/javascript'>
        function deleteUpload(id){
            if (confirm('Are you sure you want to continue ?')) {
                $.ajax({
                    type: "post",
                    url: '/securepages/uploads_edit.do',
                    data: {
                        uploadId: id
                    },
                    success: function (result) {
                        if(result.error){
                            alert("deleted with errors:" + result.error);
                        } else {
                            console.log(result.message);
                            window.location = "/securepages/uploads_edit.do";
                        }
                    },
                    error: function (result) {
                        alert("error happen");
                    }
                });
            }
        }

        function onImgLoaded(likId){
            $('#img_delete_link_' + likId).show();
        }
    </script>
</head>
<body>
<div id="container">
    <div id="header">
        <jsp:include page="/publicpages/common/header.jsp"/>
    </div>
    <div id="body">
        <span>Your Uploads:</span>
        <hr/>
        <c:forEach var="item" items="${uploads}">
            <div style="display: inline-block; border: 1px solid; padding: 10px; margin: 10px;">
                <div>
                    <img src="${item.accessLink}" style="width: 110px;" onload="javascript:onImgLoaded(${item.id});">
                </div>
                <div>
                    Size: ${sz:fileSize(item.size)}
                </div>
                <div>
                    <a id="img_delete_link_${item.id}" href="javascript:void(0);" onclick="javascript:deleteUpload(${item.id});" style="display: none;"> Delete </a>
                </div>
            </div>
        </c:forEach>
        <hr/>
    </div>
    <div id="footer">
        <jsp:include page="/publicpages/common/footer.jsp"/>
    </div>
</div>
</body>
</html>
